package org.phantom.demo.search.queuetest;

import java.util.concurrent.PriorityBlockingQueue;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;


@Component
public class TaskQueue<T extends DataLevel> {

	private PriorityBlockingQueue<T> queue = new PriorityBlockingQueue<T>();
	
	@SuppressWarnings("unchecked")
	@PostConstruct
	private void init(){
		this.pushTask((T) new Data2());
		this.pushTask((T) new Data1());
		this.pushTask((T) new Data2());
		this.pushTask((T) new Data2());
		this.pushTask((T) new Data1());
		this.pushTask((T) new Data2());
		this.pushTask((T) new Data1());
		this.pushTask((T) new Data1());
		this.pushTask((T) new Data1());
		this.pushTask((T) new Data2());
	}

	public void pushTask(T t){
		queue.offer(t);
	}
	public synchronized void pushTask(T[] t){
		for (T t2 : t) {
			queue.offer(t2);
		}
	}
	
	public PriorityBlockingQueue<T> getQueue(){
		PriorityBlockingQueue<T> temp = new PriorityBlockingQueue<T>();
		queue.drainTo(temp, 5);
		return temp;
	}
}
